﻿using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using PMS.XCMG.Util;

namespace PMS.XCMG.Entity
{
    /// <summary>
    /// 设备故障配置信息
    /// </summary>
    public partial class EquipmentFaultSetting : BusEntity
    {
        /// <summary>
        /// 设备编号
        /// </summary>
        public string EquipmentId { set; get; }
        /// <summary>
        /// 故障编码
        /// </summary>
        public string Code { get; set; }
        /// <summary>
        /// 故障名称
        /// </summary>
        public string Name { get; set; }

        /// <summary>
        /// 电气逻辑地址
        /// </summary>
        public string Address { set; get; }

        /// <summary>
        /// 故障类型
        /// </summary>
        public string FaultType { set; get; }

        /// <summary>
        /// 故障等级
        /// </summary>
        public string FaultGrade { set; get; }
    }

    public partial class EquipmentFaultSetting : BusEntity
    {
        public Equipment Equ { set; get; }
    }

    /// <summary>
    /// 实体配置
    /// OnModelCreating
    /// </summary>
    public class EquipmentFaultConfigTypeConfig : BusEntityTypeConfig<EquipmentFaultSetting>, IEntityTypeConfiguration<EquipmentFaultSetting>
    {
        public override void Configure(EntityTypeBuilder<EquipmentFaultSetting> builder)
        {
            base.Configure(builder);

            #region 主外键关系
            builder.HasOne(p => p.Equ).WithMany(o=>o.FaultConfigs).HasForeignKey(p => p.EquipmentId);
            #endregion

            #region 字段属性:最大长度,是否必需,默认值
            builder.Property(p => p.EquipmentId).HasMaxLength(EntityDefinition.DefSmallColLen).IsRequired();
            builder.Property(p => p.Code).HasMaxLength(EntityDefinition.DefSmallColLen).IsRequired();
            builder.Property(p => p.Name).HasMaxLength(EntityDefinition.DefSmallColLen).IsRequired();
            builder.Property(p => p.Address).HasMaxLength(200).IsRequired();
            builder.Property(p => p.FaultType).HasMaxLength(EntityDefinition.DefSmallColLen).IsRequired();
            builder.Property(p => p.FaultGrade).HasMaxLength(EntityDefinition.DefSmallColLen).IsRequired();
            #endregion

            #region 备注
            builder.HasComment("设备报警配置");
            builder.Property(p => p.EquipmentId).HasComment("设备编号");
            builder.Property(p => p.Code).HasComment("故障编码");
            builder.Property(p => p.Name).HasComment("故障名称");
            builder.Property(p => p.Address).HasComment("电气逻辑地址");
            builder.Property(p => p.Name).HasComment("故障名称");
            builder.Property(p => p.Address).HasComment("电气逻辑地址");
            builder.Property(p => p.FaultType).HasComment("故障类型");
            builder.Property(p => p.FaultGrade).HasComment("故障等级");
            #endregion

            #region 种子数据
            #endregion
        }
    }
}
